<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2020/7/10
  Time: 13:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>编号设置</title>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8 ? MYOA_CHARSET : htmlspecialchars($HTML_PAGE_CHARSET))?>" />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css?20190817.1">
    <link rel="stylesheet" href="/lib/layui/layui/css/common.css">
    <link rel="stylesheet" href="/lib/layui/layui/css/eleTree.css">
    <script type="text/javascript" src="/js/jquery/jquery-1.9.1.js"></script>
    <script src="/lib/layui/layui/layui.js"></script>
    <script src="/lib/jquery.form.min.js"></script>
    <%--    <script src="/lib/layui/layui/js/common.js?v=20190726" type="text/javascript" charset="utf-8"></script>--%>
    <script src="/lib/layui/layui/js/baseCode/base.js?v=2019080918:09" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/lib/layui/layui/global.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <style>
        .header{
            width:100%;
            height:45px;
            border-bottom:1px solid #9E9E9E;
            position:fixed;
            top:0px;
            z-index: 100;
            background: #fff;
        }
        .nav{
            height: 45px;
            overflow:hidden;
        }
        .nav li{
            height:28px;
            line-height:28px;
            float:left;
            font-size:14px;
            margin-left:20px;
            margin-top:6px;
            cursor:pointer;
        }
        .space{
            width:2px;
            margin-left:16px;
        }
        .pad{
            padding:3px 10px;
            line-height:28px;
        }
        .select{
            background-color:#2F8AE3;
            color:#fff;
            border-radius:20px;
            -webkit-border-radius:20px;
            -moz-border-radius:20px;
            -o-border-radius:20px;;
            -ms-border-radius:20px;
        }
        .content{
            width: 80%;
            margin: 20px auto;
        }
        .locality-p{
            height: 40px;
            background: #3791DA;
            color: #fff;
            font-size: 18px;
            padding-left: 20px;
            /*text-align: center;*/
            line-height: 40px;
            border-bottom:1px solid #9E9E9E;
        }
        .locality,.farmer{
            border:1px solid #9E9E9E;
        }
        .layui-form{
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            color: #404060;
        }
        /*.layui-input, .layui-textarea {*/
        /*    display: block;*/
        /*    width: 400px;*/
        /*    padding-left: 10px;*/
        /*    margin-left: 15px;*/
        /*}*/
        .layui-btn-normal{
            margin-top: 20px;
            width: 130px;
            border-radius: 10px;
            background-color: #3791DA;
        }
        .rights{
            width: 69%;
            margin-left: 2%;
            border:1px solid #9E9E9E;
        }
        .rightD1{
            margin: 15px;
            text-align: center;
            border: 1px solid;
            padding: 6px 0;
            border-radius: 5px;
        }
        .enable{
            background: #e5e5e5;
        }
        .layui-form-label{
            float: left;
            display: block;
            padding: 9px 15px;
            width: 90px;
            font-weight: 400;
            line-height: 20px;
            text-align: right;
            padding-left: 0;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="content">
        <%--        局编号设置--%>
        <div class="locality">
            <p class="locality-p">局编号设置</p>
            <form class="layui-form" lay-filter="formunitType1" style="padding: 10px 0">

                <input type="text" name="setId" style="display: none;">

                <div class="jubu">
                    <label class="layui-form-label" style="text-align: right" id="year">年份：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="noYear" class="layui-input" id="test2" placeholder="yyyy" lay-filter="years">
                    </div>
                </div>
                <div  style="margin-top: 10px">
                    <label class="layui-form-label rightLa" style="text-align: right;">局编号计数器:</label>
                    <div class="layui-input-inline">
                        <input type="text" value="" id="noConter" name="noConter" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <%--            <div class="ceshi"> </div>--%>
                <button type="button" class="layui-btn layui-btn-normal" lay-submit lay-filter="unitType1">保存</button>
            </form>
        </div>
        <%--    主合同及子合同--%>
        <div style="margin-top: 20px;border:1px solid #9E9E9E">
            <p class="locality-p" >承包单位编号设置</p>
            <div style="display: flex">
                <div class="farmer lefts" style="margin-top: 20px;border:1px solid #9E9E9E; width: 30%;">
                    <p class="locality-p">主合同</p>
                    <ul id="contract">

                    </ul>
                </div>
                <div class="rights farmer" style="margin-top: 20px;border:1px solid #9E9E9E;position: relative">
                    <div  style="margin-top: 10px;width: 100%">
                        <label class="layui-form-label rightLa" style="width:30%;text-align: right" id="yearRit">年份：</label>
                        <div class="layui-input-inline" style="width: 45%;">
                            <input type="text"  style="width: 100%;" name="noYear" class="layui-input" id="test3" placeholder="yyyy" lay-filter="years" class="layui-input">
                        </div>
                    </div>
                    <form class="layui-form rightsFrom"  lay-filter="rightsFrom" style="padding: 10px 0">

                    </form>
                </div>
            </div>
            <div style="display: flex;text-align: center;justify-content: center;">
                <button  name="save" type="button" style="margin: 10px 0;" class="layui-btn layui-btn-normal baocun" >保存</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script>
    var form,layer,layedit,laydate;

    //局编号查询
    function unitType1(value){
        $.get('/ContractNoSet/findNoSet',{
            noYear: value,
            unitType:1
        },function(res){
            if (res.flag && res.obj.length>0){
                // var obj0=res.obj[0];
                var datas=res.obj;
                //给表单赋值
                form.val("formunitType1", {
                    "noConter": datas[0].noConter,
                    "setId": datas[0].setId,
                    "noYear":value
                });
                laydate.render({
                    elem: '#test2'
                    ,type: 'year'
                    ,value:value
                    ,done: function(value, date, endDate){
                        unitType1(value);
                    }
                });
            }
            else{
                laydate.render({
                    elem: '#test2'
                    ,type: 'year'
                    ,value:value
                    ,done: function(value, date, endDate){
                        unitType1(value);
                    }
                });
                $('#noConter').val('');
            }
        });
    }

    //回显input
    function clickD(hthis , contractNo){
        if (contractNo == undefined){
            contractNo = $(hthis).attr('contractNo');
            //点击追加样式
            $(hthis).addClass("enable").siblings().removeClass("enable");
        }
        //承包单位input框的值
        $.ajax({
            url:'/ContractNoSet/findNoSet',
            dataType:'json',
            type:'get',
            data:{
                unitType:'2',
                mainContractNos:contractNo,
                noYear: $('#test3').val()
            },
            success:function(res){
                //    渲染input框
                var datas4=res.obj
                if(datas4.length>0){
                    for (var x in datas4) {
                        $('#'+datas4[x].unitCode).val(datas4[x].noConter);
                        $('#'+datas4[x].unitCode).attr('setId' , datas4[x].setId);
                    }
                }else{
                    $('input[name="noConter2"]').val('');
                }
            }
        })
    }

    //承包单位保存按钮
    $("button[name='save']").click(function(){
        var arr = [];
        $('form[lay-filter="rightsFrom"]').find('input[name="noConter2"]').each(function(index,element){
             var setId = $(element).attr('setId');
            if (setId != undefined){
                var object = new Object();
                object['noConter'] = $(element).val();
                object['noYear'] = $('#test3').val();
                object['setId'] = setId;
                object['unitType'] = '2';
                arr.push(object);
            }
        });
        $.post('/ContractNoSet/editNoSet',{
            jsonNoSet : JSON.stringify(arr)
        },function(res){
            if (res.flag){
                layer.msg('保存成功',{icon:1});
            }
        });
    })


    $(function(){
        layui.use(['form', 'layedit', 'laydate'], function(){
            form = layui.form
                ,layer = layui.layer
                ,layedit = layui.layedit
                ,laydate = layui.laydate;

            //局编号日期
            unitType1(new Date().getFullYear());

            //局编号的监听提交事件
            form.on('submit(unitType1)', function(data){
                var arr = [];
                var field = data.field;
                field['unitType'] = '1'; //判断是主合同
                arr.push(field);
                var params = JSON.stringify(arr);

                $.post('/ContractNoSet/editNoSet',{
                    jsonNoSet : params
                },function(res){
                    if (res.flag){
                        layer.msg('保存成功',{icon:1});
                    }
                });
                return false;
            });


            //承包单位编号日期
            laydate.render({
                elem: '#test3'
                ,type: 'year'
                ,value: new Date().getFullYear()
            });


            //承包单位右边
            $.ajax({
                url:'/code/getCode',
                dataType:'json',
                type:'get',
                data:{
                    parentNo:'CONTRACT_UNIT'
                },
                success:function(res){
                    var datas3 = res.obj;
                    if (res.flag){
                        var str3='';
                        for (y in datas3){
                            str3+=' <div  style="margin-top: 10px;width: 100%">\n' +
                                '                        <label class="layui-form-label rightLa" style="width: 30%;text-align: right">'+datas3[y].codeName+':</label>\n' +
                                '                        <div class="layui-input-inline" style="width: 45%;">\n' +
                                '                            <input type="text" id="'+datas3[y].codeNo+'"  name="noConter2" placeholder="请输入"  class="layui-input" style="width: 100%;" >\n' +
                                '                        </div>\n' +
                                '</div>';
                        }
                        $(".rightsFrom").html(str3);
                    }
                }
            });

            //主合同
            $.ajax({
                url:'/ContractNo/findContractNo',
                dataType:'json',
                type:'get',
                data:{
                    contractType:1
                },
                success:function(res){
                    var datas2 = res.obj;
                    if (res.flag && datas2.length > 0 ){
                        var str2='';
                        for (x in datas2){
                            str2+=' <li onclick="clickD(this)"  contractNo="'+datas2[x].contractNo+'" class="rightD1"> '+datas2[x].contractName+'</li>'
                                // '       <span class="rightD2" ></span>'
                        }
                        $("#contract").html(str2);
                        clickD(undefined,datas2[0].contractNo);
                        $("#contract li").eq(0).addClass('enable')
                    }
                }
            });
        });

    })

</script>
